;;; Factorial digit sum

;;; Problem 20

;;; n! means n × (n - 1) × ... × 3 × 2 × 1

;;; For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
;;; and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

;;; Find the sum of the digits in the number 100!


;; Idea: Seems simple. Just calculate 100! and take the digit sum. I
;; do not know, whether there is a trick in there to calculate the
;; digit sum more efficiently, but it is definitely very simple to
;; calculate the digit sum of large integers in GNU Guile.


(import
 (except (rnrs base) let-values map)
 (only (guile)
       lambda* λ)
 (prefix (lib math) math:)
 (lib debug-utils))


(displayln "sum of digits of 100!:"
           (math:digits-sum
            (math:factorial-linear 100)))
